<?php

// define variables and set to empty values
$name = $email = $gender = $comment = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $err = "";
    $name = test_input($_POST["name"]);
    if(empty($name)){
        $err = "姓名不能为空";
    }
    $email = test_input($_POST["email"]);
    if(empty($email)){
        $err = "邮箱不能为空";
    }
    $website = test_input($_POST["website"]);
    $comment = test_input($_POST["comment"]);

    $gender = test_input($_POST["gender"]);
    if(empty($gender)){
        $err = "性别不能为空";
    }

    header('Content-Type:application/json');
    if(empty($err)){
        $result = [
            "res" => "success",
            "data" => "name=" . $name
        ];
        echo json_encode($result);
    }else{
        $result = [
            "res" => "fail",
            "err" => $err
        ];
        echo json_encode($result);
    }


//    $file = $_FILES["file"];
}

function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
